﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using YAPL.Language.Core;
using YAPL.Language.Core.Exceptions;
using YAPL.Language.Core.Types;

namespace YAPL.Test.YAPL.Language.Core.Lib.GlobalFunctions {
	public class ParseIntTest {
		private readonly YAPLFunction _parseInt;

		public ParseIntTest() {
			_parseInt = GCL.Get(ClassNames.GlobalScope).Methods[FunctionNames.ParseInt];
		}

		[Fact]
		public void ValidIntShouldBeParsedCorrectly() {
			YAPLInt result = null;
			var scope = new Scope();
			scope["unnamed0"] = new YAPLString("123");
			Assert.DoesNotThrow(() => result = (YAPLInt)_parseInt.Call(scope));
			Assert.NotNull(result);
			Assert.Equal(123,result.IntValue);
		}

		[Fact]
		public void InvalidIntShouldThrowException() {
			var scope = new Scope();
			scope["unnamed0"] = new YAPLString("sdfsf");
			Assert.Throws<YAPLBadArgumentException>(() =>_parseInt.Call(scope));
		}
	}
}
